<?php

include '../../../configuration.php';

$smarty->template_dir = LOCAL_PATH.'administrator/main/templates/';
$smarty->compile_dir = LOCAL_PATH.'administrator/main/templates_c/';
$smarty->config_dir = LOCAL_PATH.'administrator/main/configs';

$smarty->compile_check = true;
//$smarty->debugging = true;

$question_id;
$choices = array();
$choices_id = array();
$choices_order = array();
$correct_value = array();
$choice_cdate = array();
$cat_title = array();

if(isset($_GET['id'])){
	$question_id = $_GET['id'];
}

$result = mysql_query("SELECT * FROM `questions` WHERE q_id = $question_id");
$result2 = mysql_query("SELECT * FROM `choices` WHERE q_id = $question_id");
$result3 = mysql_query("SELECT * FROM `categories`");
$row = mysql_fetch_assoc($result);
$q_title = $row["q_title"];
$q_cdate = $row["q_cdate"];
$cat_id = $row["cat_id"];
$complexity = $row["q_complexity"];

while($rows2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
	$choices[] = $rows2["c_title"];
	$choices_id[] = $rows2["c_id"];
	$choices_order[] = $rows2["c_order"];
	$correct_value[] = $rows2["c_correctvalue"];
}
while($rows3 = mysql_fetch_array($result3,MYSQL_ASSOC)){
	$selected = '';
	if ($cat_id == $rows3["cat_id"]) {
		$selected = "selected='selected'";
	}
	$categories[] = "<option value='".$rows3["cat_id"]."' $selected >".$rows3["cat_title"]."</option>";
}
$smarty->assign('q_id',$question_id);
$smarty->assign('q_title',$q_title);
$smarty->assign('comp',$complexity);
$smarty->assign('q_cdate',$q_cdate);
$smarty->assign('q_udate',date("Y-m-d H:i:s"));
$smarty->assign('categories',$categories);
$smarty->assign('hidden',"<input type='hidden' name='udate' value=".date('Y-m-d H:i:s')." />");
$smarty->assign('choices',$choices);
$smarty->assign('choices_id',$choices_id);
$smarty->assign('choices_order',$choices_order);
$smarty->assign('correct_value',$correct_value);

include '../../check.php';
if ($checking == 1)
	$smarty->display('modifing_question.tpl');
else echo "You are not autorised"; exit;

?>